﻿//  -------------------- iSharePoint -------------------- //
// 
//  Company:	IT Complex, LLC
//  Project:	Smart.Common
//  File name:	SqlConst.cs
//  Developer:	Solomatov Igor
//  Created:	15.04.2012
// 
//  -------------------- iSharePoint -------------------- //

namespace Smart.Common
{
	/// <summary>
	/// SQL constants
	/// </summary>
	public static class SqlConst
	{
		public static readonly string ConnectionApplicationName =
			"SqlContext-{0}-{1}-{2}";

		public static readonly string AllObjectsIn =
			"SELECT [object_id], [name], [type] FROM sys.all_objects WHERE [name] in ({0})";

		public static readonly string AllColumnsFor =
			"SELECT c.column_id, c.name, t.name, c.is_identity, c.is_computed FROM sys.all_columns c INNER JOIN sys.types t ON c.system_type_id = t.system_type_id WHERE c.object_id = {0}";

		public static readonly string AllParametersFor =
			"SELECT p.parameter_id, p.name, t.name FROM sys.all_parameters p INNER JOIN sys.types t ON p.system_type_id = t.system_type_id WHERE p.object_id = {0}";

		public static readonly string AllParametersForSP =
			"SELECT p.parameter_id, p.name, t.name FROM sys.all_parameters p INNER JOIN sys.types t ON p.system_type_id = t.system_type_id INNER JOIN sys.all_objects o ON p.object_id = o.object_id WHERE o.[name] = {0}";

		public static readonly string QueryObjectById =
			"SELECT * FROM {0} WHERE {1} = {2}";

		public static readonly string DeleteObjectById =
			"DELETE FROM {0} WHERE {1} = {2}";

		public static readonly string InsertItemStandart =
			"INSERT INTO {0} ({1}) VALUES ({2})\r\nSELECT * FROM {0} WHERE ({3} = {4})";

		public static readonly string InsertItemIdentity =
			"INSERT INTO {0} ({1}) VALUES ({2})\r\nSELECT * FROM {0} WHERE ({3} = @@IDENTITY)";

		public static readonly string UpdateItem =
			"UPDATE {0} SET {1} WHERE ({2} = {3})\r\nSELECT * FROM {0} WHERE ({2} = {3})";

		public static readonly int NormalConnectionTimeout = 10;

		public static readonly int SlowCommandTimeout = 3600;
		public static readonly int NormalCommandTimeout = 60;
		public static readonly int FastCommandTimeout = 10;
	}
}